package com.ara.common.kernel.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.ara.common.kernel.R;
import com.ara.common.kernel.base.BaseDialog;
import com.ara.common.kernel.bean.UpgradeBean;
import com.ara.common.kernel.databinding.DialogUpgradeBinding;

/**
 * Created by XieXin on 2018/12/10.
 * 版本更新 Dialog
 */
public class UpgradeDialog extends Dialog {
    private DialogUpgradeBinding binding;
    private UpgradeBean upgradeBean;
    private String content;
    private View.OnClickListener updateListener;
    private View.OnClickListener closeListener;

    public UpgradeDialog(@NonNull Context context, @NonNull UpgradeBean upgradeBean,
                         @NonNull View.OnClickListener updateListener,
                         @NonNull View.OnClickListener closeListener) {
        super(context, R.style.DialogBgTranslucentStyle);
        this.upgradeBean = upgradeBean;
        this.content = upgradeBean.getContent();
        this.updateListener = updateListener;
        this.closeListener = closeListener;
    }

    public void setUpgradeBean(UpgradeBean upgradeBean) {
        this.upgradeBean = upgradeBean;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setUpdateListener(View.OnClickListener updateListener) {
        this.updateListener = updateListener;
    }

    public void setCloseListener(View.OnClickListener closeListener) {
        this.closeListener = closeListener;
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogUpgradeBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.btnUpdate.setOnClickListener(updateListener);
        binding.btnCancel.setOnClickListener(v -> {
            dismiss();
            if (closeListener != null) closeListener.onClick(v);
        });

        if (upgradeBean.isStatus()) {
            binding.lineView.setVisibility(View.GONE);
            binding.btnCancel.setVisibility(View.GONE);
        }

        BaseDialog.setDialogWidth(getWindow(), getContext());

        binding.tvContent.setText(content);
    }

}
